/*
 * 文件名：NoticeInfoServiceImpl.java
 * 版权：Copyright by www.huawei.com
 * 描述：
 * 修改人：Administrator
 * 修改时间：2016年3月29日
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */

package com.zcsy.manage.service.news.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zcsy.commons.constants.Constants;
import com.zcsy.manage.model.news.NoticeInfo;
import com.zcsy.manage.persistence.news.NoticeInfoDao;
import com.zcsy.manage.service.news.INoticeInfoService;
import com.zcsy.manage.service.system.impl.SystemComService;

/**
 * @Title: NoticeInfoServiceImpl.java
 * @Package： com.zcsy.manage.service.news.impl 
 * @Description: 通知信息service层接口实现类
 *
 * @author liuying 1075817474@qq.com
 * @Copyright: 2015 武汉中财数元信息技术有限公司 All rights reserved.
 * @date 2016年3月29日
 * @version 1.0
 * @see JDK1.7.0_75
 * @since
 */
@Service
public class NoticeInfoServiceImpl extends SystemComService implements INoticeInfoService{
	
	@Autowired
	private NoticeInfoDao noticeInfoDao;
	
	@Override
	public int insert(NoticeInfo noticeInfo) {
		return noticeInfoDao.insert(noticeInfo);
	}

	@Override
	public int update(NoticeInfo noticeInfo) {
		NoticeInfo oldInfo = noticeInfoDao.selectByPrimaryKey(noticeInfo.getId());
		
		oldInfo.setTitle(noticeInfo.getTitle());
		oldInfo.setCellId(noticeInfo.getCellId());
		oldInfo.setType(noticeInfo.getType());
		oldInfo.setUserType(noticeInfo.getUserType());
		oldInfo.setContent(noticeInfo.getContent());
		oldInfo.setSort(noticeInfo.getSort());
		oldInfo.setLogo(noticeInfo.getLogo());
		oldInfo.setUpdateTime(noticeInfo.getUpdateTime());
		oldInfo.setReadAccount(Constants.INT_ZERO);
 		
		return noticeInfoDao.updateByPrimaryKey(oldInfo);
	}

	@Override
	public int delete(String id) {
		return noticeInfoDao.deleteByPrimaryKey(id);
	}

	@Override
	public NoticeInfo selectByPrimaryKey(String id) {
		return noticeInfoDao.selectByPrimaryKey(id);
	}

	@Override
	public List<NoticeInfo> selectByKeyword(NoticeInfo noticeInfo) {
		return noticeInfoDao.selectByKeyword(noticeInfo);
	}
	
	@Override
	public List<NoticeInfo> getNoticeInfoList(String cellId,String userId) {
	    Map<String, Object> map = new HashMap<String, Object>();
        map.put("userId", userId);
        map.put("cellId", cellId);
	    return noticeInfoDao.getNoticeInfoList(map);
	}

	@Override
	public List<NoticeInfo> selectCountList(String userId,String cellId) {
		return noticeInfoDao.selectCountList(userId,cellId);
	}

	@Override
	public int selectUnreadCount(String userId, String cellId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("userId", userId);
		map.put("cellId", cellId);
		return noticeInfoDao.selectUnreadCount(map);
	}

	@Override
	public int updateSort(NoticeInfo noticeInfo) {
		return noticeInfoDao.updateSort(noticeInfo);
	}

	@Override
	public List<NoticeInfo> getNewNoticeList(String cellId, Integer limit) {
		return noticeInfoDao.getNewNoticeList(cellId, limit);
	}

	@Override
	public List<String> selectIdList(String cellId) {
		return noticeInfoDao.selectIdList(cellId);
	}

	@Override
	public Integer updateReadCount(String id) {
		return noticeInfoDao.updateReadCount(id);
	}
	
}
